package com.heisenhub.uua.hander;

import com.heisnenhub.common.module.utils.Api;
import com.heisnenhub.common.module.utils.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@Slf4j
public class HubAuthenticationFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        log.info("【登录失败】{}",exception.getMessage());
        ResponseUtils.makeResponse(response, MediaType.APPLICATION_JSON_UTF8_VALUE,HttpServletResponse.SC_OK, Api.fail(exception.getMessage()));

    }
}
